<?php 
$GLOBALS['Md'] = "RHEID348";
$GLOBALS['Pd'] = "B";
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
MYTCONN();
	$qrDept = '';
	if (isset($_POST['ivtDepartment']) && $_POST['ivtDepartment'] > 0) {
	$qrDept = ' AND main_offices.ref = '.$_POST['ivtDepartment'];
	}
	if (!isset($_POST['ivtID'])) { $_POST['ivtID'] = 0; }
	$GET = $GLOBALS['MYT']->db_array("SELECT 
						CONCAT(incCode,IF(main_offices.ref>10,office_number,LEFT(UPPER(main_offices.name),4)),YEAR(iveEntryDate),LPAD(iveDeptReference,4,'00')) AS COL1, 
						CONCAT(iviName,' ',iveDescription) AS COL2,
						iveQuant AS COL3, 
						ivePrice AS COL4,
						iveQuant*ivePrice AS COL5,
						iveEntryDate AS COL6,
						main_users.name AS COL7
			FROM systemoffice.inventory_entries
			INNER JOIN systemoffice.inventory_items ON iviID = iveItem
			INNER JOIN systemoffice.main_users ON iveEntryUser = main_users.ref
			INNER JOIN systemoffice.main_offices ON iveDepartment = main_offices.ref
			INNER JOIN systemoffice.inventory_cat ON ivcID = iveCat
			WHERE iveInventory = {$_POST['ivtID']}
			{$qrDept}");
	$CARD = $GET[0]; 
	?>
<script charset="utf-8" type="text/javascript">
disableSelection(document.getElementById("BoardPanel"));

Ext.onReady(function(){

 $elem = 170;
 var  windowWidth = 0, windowHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	windowWidth = window.innerWidth
	windowHeight = window.innerHeight-$elem;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight-$elem;
  } 

    Ext.QuickTips.init();

    var myData = [
	<?php   
	for ($i=1;$i<=$CARD;$i++) { 
	echo "[{$i},'{$GET[$i]['COL1']}','{$GET[$i]['COL2']}','{$GET[$i]['COL3']}','{$GET[$i]['COL4']}','{$GET[$i]['COL5']}','{$GET[$i]['COL6']}','{$GET[$i]['COL7']}']";
		if ($i<$CARD) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
               {name: 'COL1', type: 'string'},
               {name: 'COL2', type: 'string'},
               {name: 'COL3', type: 'string'},
	       {name: 'COL4', type: 'string'},
               {name: 'COL5', type: 'string'},
               {name: 'COL6', type: 'string'},
               {name: 'COL7', type: 'string'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "CÓdigo Etiqueta", width: 120, sortable: true, locked:true, dataIndex: 'COL1'},
        {header: "Descrição", width: 300, sortable: true, locked:true, dataIndex: 'COL2'},
        {header: "Quantidade", width: 80, align:'right', sortable: true, dataIndex: 'COL3'},
        {header: "PreÇo Unitário", align:'right',width: 150, sortable: true, locked:true,dataIndex: 'COL4'},
        {header: "PreÇo Total", width: 120, align:'right', sortable: true, locked:true,dataIndex: 'COL5'},
        {header: "Data Levantamento", width: 120, sortable: true, locked:true,dataIndex: 'COL6'},
        {header: "Por", width: 120, sortable: true, locked:true,dataIndex: 'COL7'}
    ]);
	
   var selmode = new Ext.grid.RowSelectionModel({});
   new Ext.grid.GridPanel({
		ds: ds,
		cm: colModel,
		sm: selmode,
		height: windowHeight,
		border: true,
        renderTo: 'BoardPanel'
    });	
});
</script>